{extend name='common/common' /}

{block name="style"}
<style type="text/css">
    a:hover{
      text-decoration:underline;
      color:#ff00ff;
    }
    a{
        color：#888;!important;
    }
    .container-fluid .btn.btn-sm{
        float: right;
        margin-left: 10px;
    }
    .container-fluid{
        padding-right: 0px;
    }
    .layui-form-label{
        padding-left: 0px;
        width: 85px;
    }
    .layui-input-block{
        margin-left: 85px;
    }
    .layui-form-item{
        margin-bottom: 0px;
    }
		#cusTable tr{
			cursor: pointer;
		}
</style>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>订单列表</h5>
        </div>
        <div class="ibox-content">
            <!--   删除   -->
            <div class="container-fluid form-inline pull-right" style="margin-top: 10px">
                <button class="btn btn-danger btn-sm getIDs" data-delete="{:url('finance/deleteOrder')}" data-param="">删除订单</button>
            </div>
            <!--搜索框开始 pull-right-->
            <form id='commentForm' role="form" method="post" class="form-inline pull-left">
                <div class="content clearfix m-b">
                    <div class="form-group">
                        <label>姓名：</label>
                        <input type="text" class="form-control" id="stu_name" name="stu_name">
                    </div>
                    <div class="form-group">
                        <label>订单号(收据号)：</label>
                        <input type="text" class="form-control" id="order_sn" name="order_sn">
                    </div>
					<div class="form-group">
                        <label>学校：</label>
						<div class="input-group col-sm-8">
							<select name="school_id" id="school_id" class="form-control" >
								<option value="">请选择</option>
								<?php foreach($schoolArr as $val): ?>
									<option value="<?=$val['id'];?>"><?=$val['name'];?></option>
								<?php endforeach;?>
							</select>
						</div>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
                        </button>
                    </div>
                </div>
            </form>
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example">
                    <table id="cusTable">
                        <thead>
                        <th>checkbox</th>
                        <!-- <th class="text-center" data-field="id">订单id</th> -->
                        <th class="text-center" data-width="150px" data-field="order_sn">收据号</th>
                        <th class="text-center" data-width="100px" data-field="stu_name">报名人</th>
                        <th class="text-center" data-width="200px" data-field="school">院校</th>
                        <th class="text-center" data-width="200px" data-field="major">专业</th>
                        <th class="text-center" data-width="100px" data-field="gradeN">层次</th>
                        <th class="text-center" data-width="100px" data-field="systemN">学制</th>
                        <th class="text-center" data-width="100px" data-field="acquisition_modeN">授课模式</th>
                        <th class="text-center" data-width="100px" data-field="payment_methodN">缴费方式</th>
                        <th class="text-center" data-width="100px" data-field="pay_typeN">支付方式</th>
                        <th class="text-center" data-width="100px" data-field="total_amount">总金额</th>

                        <th class="text-center" data-width="100px" data-field="tuition">学费</th>
                        <th class="text-center" data-width="100px" data-field="registration">报名费</th>
                        <th class="text-center" data-width="100px" data-field="material_cost">资料费</th>
                        <th class="text-center" data-width="100px" data-field="photo_collection">照片采集费</th>

                        <th class="text-center" data-width="100px" data-field="statusN">订单状态</th>
                        <th class="text-center" data-width="100px" data-field="c_time">创建时间</th>
                        <th class="text-center" data-width="200px" data-field="remarks">备注</th>
                        <th class="text-center" data-width="250px" data-field="operate">操作</th>
                        </thead>
                    </table>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
<!-- 退款订单 -->
<div id="deleteOre" style="display: none;padding: 15px;padding-bottom: 0px">
    <div class="layui-form-item">
        <label class="layui-form-label">退款金额:</label>
        <div class="layui-input-block">
            <input type="number" id="deleteNum" name="deleteNum" required  lay-verify="required" placeholder="退款金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注:</label>
        <div class="layui-input-block">
            <textarea name="remarks" id="remarks" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
</div>
<!-- 费用收取 -->
<div id="total_many" style="display:none;padding: 10px;padding-left:0px;">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">报名费</label>
            <div class="layui-input-block">
                <input id="registration" name="registration" type="number" min="0" value="0" class="form-control">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学费</label>
            <div class="layui-input-block">
                <input id="tuition" name="tuition" type="number" min="0" value="0" class="form-control">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">材料费</label>
            <div class="layui-input-block">
                <input id="material_cost" name="material_cost" type="number" min="0" value="0" class="form-control">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">采集费</label>
            <div class="layui-input-block">
                <input id="photo_collection" name="photo_collection" type="number" min="0" value="0" class="form-control">
            </div>
        </div>
    </form>
</div>
<!-- 备注信息 -->
<div class="remarksBox" style="display:none;padding:15px;"></div>
{/block}


{block name="script"}
<script src="__JS__/tableExport.js"></script>
<script src="__JS__/bootstrap-table-export.js"></script>
<script type="text/javascript">
	function DoOnMsoNumberFormat(cell, row, col) {
		var result = "";
		if (row > 0 && col == 0)
			result = "\\@";
		return result;
	}
    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: "{:url('Finance/businOrder')}", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 25,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [25, 50, 75, 100, 150],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
						resizable:true,//可变宽列表
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
			      showToggle:false,
            showColumns:true,
            showExport: false,  //是否显示导出按钮
            exportTypes:['excel'],  //导出文件类型
            Icons:'glyphicon-export',
            exportOptions:{
                // ignoreColumn: [0,1],  //忽略某一列的索引
                fileName: '订单统计',  //文件名称设置
                worksheetName: 'sheet1',  //表格工作区名称
                tableName: '订单统计报表',
                excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
                onMsoNumberFormat: DoOnMsoNumberFormat
            },
            columns : [{
                checkbox: true,
                formatter:function(value,row,index){
                    if (row.state == true){
                        return {
                            checked : value,//设置选中
                        };
                    }
                    return value;
                },
            }],
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    stu_name:$('#stu_name').val(),
                    order_sn:$('#order_sn').val(),
					school_id:$('#school_id').val(),
                };
                return param;
            },
            onLoadSuccess: function(res){ //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            },
						onDblClickRow: function(row) {
							$(".remarksBox").html(row.remarks);
							var rmBox = layer.open({
								type:1,
								title:"备注信息",
								area:["300px","200px"],
								content:$(".remarksBox")
							});
						},
        });
    }

    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();
        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);

        $('.getIDs').on('click',function(){
            var checkedOn= $('#cusTable').bootstrapTable('getSelections');
            var IDs = '';
            for(var i=0;i<checkedOn.length;i++){
                if(i == 0){
                    IDs = checkedOn[0].id;
                }else{
                    IDs += ',' + checkedOn[i].id;
                }
            }
            $('.getIDs').attr('data-param',IDs);
        })
    });

    function articleDel(id){
        layer.confirm('确认删除此文章?', {icon: 3, title:'提示'}, function(index){
            $.getJSON("{:url('articles/articleDel')}", {'id' : id}, function(res){
                if(1 == res.code){
                    layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                        initTable();
                    });
                }else if(111 == res.code){
                    window.location.reload();
                }else{
                    layer.alert(res.msg, {title: '友情提示', icon: 2});
                }
            });
            layer.close(index);
        })
    }
    //发起退款
    function deleteOre(id){
        layer.open({
            type: 1,
            area: ['400px','300px'],
            btn: ['确认', '取消'],
            content: $('#deleteOre') ,
            yes: function(){
                //获取退款金额
                var deleteNum = parseFloat($('#deleteNum').val());
                var remarks = $('#remarks').val();
                if(deleteNum == NaN){
                    layer.msg('请填写正确格式', {time : 1000});
                    return false;
                }
                $.post("{:url('finance/Gathering')}",{
                    deleteNum:deleteNum,
                    orderId:id,
                    remarks:remarks
                },function (res) {
                    if (res.code == 1){
                        layer.msg(res.msg, {time : 1000},function(){
                            layer.closeAll();
                            initTable();
                        });
                    }else{
                        layer.msg(res.msg, {time : 1000});
                    }
                })
            }
        });
    }
    // 确认订单
    var sureOrder = function(id){
        let order_id = id;
        // console.log(order_id);
        $.post("{:url('finance/suerOrder')}",{
            order_id:order_id
        },function(data){
            console.log(data);
            if(data.code == 1){
                layer.msg('订单已确认', {time : 1000},function(){
                    layer.closeAll();
                    initTable();
                });
            }else{
                layer.msg('操作失败', {time : 1000});
            }
        });
    }
    //费用收取
    var total_many = function(id){
        layer.open({
            type: 1,
            title: '费用收取',
            area: ['400px','300px'],
            btn: ['确认', '取消'],
            content: $('#total_many') ,
            yes: function(){
                //获取退款金额
                let order_id  = id;
                let registration = parseFloat($('#registration').val());//报名费
                let tuition = parseFloat($('#tuition').val());//学费
                let material_cost = parseFloat($('#material_cost').val());//材料费
                let photo_collection = parseFloat($('#photo_collection').val());//照片采集费
                $.post("{:url('finance/total_many')}",{
                    order_id        : order_id,
                    registration    : registration,
                    tuition         : tuition,
                    material_cost   : material_cost,
                    photo_collection:photo_collection,
										is_append:1
                },function (res) {
                    if (res.code == 1){
                        layer.msg(res.msg, {time : 1000},function(){
                            layer.closeAll();
                            initTable();
                        });
                    }else{
                        layer.msg(res.msg, {time : 1000});
                    }
                })
            }
        });
    }
</script>
{/block}
